#include "session.h"

Session::Session()
{

}

Session::Session(const QString &item, const QDateTime &datetime):
    dateTime(datetime)
{
    username = item.split(" : ").at(0);
    ip = item.split(" : ").at(1);
}

bool Session::isKeepAlive(const QTime &currentTime)
{
    QTime time = dateTime.time();
    int msecs_to = time.msecsTo(currentTime);
    if(msecs_to > 5000) return false;       // 如果时间戳超过5秒则用户可能异常断线
    return true;
}

void Session::updateDateTime(const QDateTime &currentDateTime)
{
    dateTime = currentDateTime;
}

